; Copyright (c) 2006, Michael Borgmann <code@lechuck.de>
; This code is released under the new BSD license

; The boot loader can be distributed with a kernel as an OS.
; For testing I recommend the smallkernel.asm kernel
; 1. Mount a floppy first
; 2. Build kernel: % nasm smallkernel.asm
; 3. Build boot loader: % nasm bootloader.asm
; 4. Create OS image: % cat bootloader kernel > SmallOS.img
; 5. Write to floppy: % dd if=SmallOS.img of=/dev/fd0
; 6. Boot OS. With QEMU: % qemu -fda /dev/fd0


; set program address to boot sector
	org	0x7c00

; program start
start:
	; update segment registers
	mov	ax, cs
	mov	ds, ax
	mov	es, ax

; reset floppy drive
reset:
	mov	ax, 0
	mov	dl, 0		; drive = 0
	int	0x13
	jc	reset		; ERROR: reset again

read:
	mov	ax, 0x1000	; es:bx = 1000:0000
	mov	es, ax
	mov	bx, 0

	mov	ah, 2		; load disk data to es:bx
	mov	al, 5		; load 5 sectors
	mov	ch, 0		; cylnder = 0
	mov	cl, 2		; sector = 2
	mov	dh, 0		; head = 0
	mov	dl, 0		; drive = 0
	int	13h		; read!

	jmp	0x1000:0000	; jump to program

; make proper boot block
times 510-($-$$) db 0		; make proper file size
dw 0AA55h			; append boot signature
